package com.qijian.maindata.tools.poi;

import cn.hutool.core.collection.CollectionUtil;
import com.qijian.common.utils.poi.ExcelCustomizationTemplateAdapter;
import com.qijian.maindata.domain.vo.BomDetailVo;
import com.qijian.maindata.domain.vo.LineProcessVo;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

/**
 * @author gw
 */
public class ExcelCustomizationBomLineProcess extends ExcelCustomizationTemplateAdapter {

    public ExcelCustomizationBomLineProcess() {
        super("工序流转卡.xls");
    }

    @Override
    public String writeSheet(Object obj) {
        BomDetailVo o = (BomDetailVo) obj;

        if (o == null) {
            return "";
        }
        Row row5 = getRow(5);
        Cell r5c9 = getCell(row5, 9);
        r5c9.setCellValue(o.getItemCode());
        Row row6 = getRow(6);
        Cell r6c2 = getCell(row6, 2);
        r6c2.setCellValue(o.getItemName());
        Cell r6c7 = getCell(row6, 7);
        r6c7.setCellValue(o.getPartNo());
        Cell r6c9 = getCell(row6, 9);
        r6c9.setCellValue(o.getDrawingNo());
        if (CollectionUtil.isNotEmpty(o.getProcessList())) {
            int no = 1;
            int startRow = 9;
            insertRow(startRow, o.getProcessList().size(), 12);
            for (LineProcessVo lineProcess : o.getProcessList()) {
                Row row = getRow(startRow++);
                Cell cell0 = getCell(row, 0);
                cell0.setCellValue(no++);
                Cell cell1 = getCell(row, 1);
                cell1.setCellValue(lineProcess.getProcessName());
            }
        }
        return o.getItemName();
    }
}
